//
//  AccountViewController.m
//  MaskMachine
//
//  Created by yuanyuan on 15-3-1.
//  Copyright (c) 2015年 hanjiaxue. All rights reserved.
//

#import "AccountViewController.h"
#import "AppDelegate.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "LevelViewController.h"
#import "RechargeViewController.h"
#import "RechargeRecordViewController.h"
#import "SetPasswordViewController.h"
#import "DataDownloadViewController.h"
#import "WithdrawViewController.h"
#import "FinishWithDrawViewController.h"
#import "WithDrawJiLuViewController.h"
#import "YoungAllData.h"
#import "InfoViewController.h"
#import "GMDCircleLoader.h"
#import "SetPayViewController.h"
#import "Alart_ZhiFuView.h"
#import "SettViewController.h"
@interface AccountViewController ()<YoungDelegate,UITextFieldDelegate>
{
    UIImageView *titleBgView;
    UIView *middleView;
    UIView *belowView;
    UIView *jiesuanView;
    UIView *bbView;
    UIView *paymentView;
    UIView *settlementView;
    
    NSString *zName;
    NSString *zKeyong;
    
    Alart_ZhiFuView *_zhiFuAlartView;//提交订单时的弹出框
    UIView *_alertBackview;
    
    UIView *zBack;
    UIView *views;
    UIView *alertView;
    //缴纳近
    UILabel *paymentLabel;
    UILabel *paymentValue;
    UIButton *paymentBtn;
    //去结算
    UILabel *settlementLabel;
    UILabel *settlementValue;
    UIButton *settlementBtn;
    
}
@property (nonatomic, copy) NSString *boolbalance; //选择余额
@property (nonatomic, copy) NSString *IsPayOffDeposit; //是否缴纳保证金
@end

@implementation AccountViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [self colorWithHexString:@"#F5F5F5"];
    
    self.navigationController.navigationBarHidden=YES;
    
    [self initNav];
    
    navTitle.text = @"账号";
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(backShua) name:@"backShua" object:nil];
    [GMDCircleLoader setOnView:self.view withTitle:@"加载中···" animated:YES];

    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainUserInfo:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"]];
    
    
    //当提现成功后刷新数据
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updataInfo) name:@"updataInfo" object:nil];
}
#pragma mark - 返回刷新
-(void)backShua{
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data gainUserInfo:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"]];
}
-(void)updataInfo{
    NSLog(@"调用接口刷新数据");
}

#pragma mark - 微商账户信息回调
-(void)userInfo:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
        NSLog(@"%@",[[sign objectForKey:@"data"] objectForKey:@"LevelName"]);
    
    if (titleBgView) {
        self.ticheng.text = [NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"AccountAmount"]];
        self.dongjie.text =[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"FreezeAmount"]];
        NSInteger total = [self.ticheng.text integerValue];
        NSInteger freeze = [self.dongjie.text integerValue];
        NSInteger keyong = total - freeze;
        self.keyong.text = [NSString stringWithFormat:@"%ld",(long)keyong];
        zKeyong =[NSString stringWithFormat:@"%ld",(long)keyong];
    }else{
        self.IsPayOffDeposit = [NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"IsPayOffDeposit"]];
    [self createAccountView:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"RealName"]]
               andLevelName:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"LevelName"]]
            andDiscountRate:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"DiscountRate"]]
            andProfitAmount:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"ProfitAmount"]]
              andSellAmount:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"SellAmount"]]
         andFatherAgentName:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"FatherAgentName"]]
             andFatherPhone:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"FatherPhone"]]
           andAccountAmount:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"AccountAmount"]]
            andFreezeAmount:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"FreezeAmount"]]
            andMobileNumber:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"MobileNumber"]]
           andDepositAmount:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"DepositAmount"]]
         andExpressFeeTotal:[NSString stringWithFormat:@"%@",[[sign objectForKey:@"data"] objectForKey:@"ExpressFeeTotal"]]];
    }
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}

-(void)clickBackBtn{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 退出按钮
-(void)quitButtonAction{
    NSLog(@"退出");

}

-(void)createAccountView:(NSString *)RealName andLevelName:(NSString *)LevelName andDiscountRate:(NSString *)DiscountRate andProfitAmount:(NSString *)ProfitAmount andSellAmount:(NSString *)SellAmount andFatherAgentName:(NSString *)FatherAgentName andFatherPhone:(NSString *)FatherPhone andAccountAmount:(NSString *)AccountAmount andFreezeAmount:(NSString *)FreezeAmount andMobileNumber:(NSString *)MobileNumber andDepositAmount:(NSString *)DepositAmount andExpressFeeTotal:(NSString *)ExpressFeeTotal{
    
    self.scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width,self.view.frame.size.height)];
    if (SCREEN_HEIGHT < 500) {
        self.scroller.contentSize = CGSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT+25+50+40+100);
    }else{
        self.scroller.contentSize = CGSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT+40+100);
    }
    [self.view addSubview:self.scroller];
    
    titleBgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH, 270)];
    titleBgView.backgroundColor = [UIColor whiteColor];
    titleBgView.userInteractionEnabled = YES;
    [self.scroller addSubview:titleBgView];
    
    
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 1, 80, 40)];
    label1.text = @"欢迎回来";
    label1.textColor = [UIColor blackColor];
    label1.font = [UIFont systemFontOfSize:16];
    [titleBgView addSubview:label1];
    
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(label1.right, label1.top, 200, 40)];
    self.name.text = RealName;
    zName = RealName;
    self.name.font = [UIFont systemFontOfSize:16];
    [titleBgView addSubview:self.name];
    
    [self createrOffLineUI:CGRectMake(10, self.name.bottom, SCREEN_WIDTH-20, 0.5)];
    
    UILabel *label2 = [self createAccountLabel:CGRectMake(10, label1.bottom+10, 100, 25) andTitle:@"您的代理等级："];
    label2.font = [UIFont systemFontOfSize:14];
    label2.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    
    
    self.agentLevel = [self createAccountLabel:CGRectMake(label2.right, label1.bottom+10, 80, 25) andTitle:LevelName];
    
    
    //    self.agentLevel = [self createAccountLabel:CGRectMake(label2.right, label2.top, 80, 20) andTitle:single.buyerModel.daili_id];
    self.agentLevel.font = [UIFont systemFontOfSize:14];
    //self.agentLevel = [self createAccountLabel:CGRectMake(label2.right, label2.top, 80, 20) andTitle:@"13级"];
    
//    UILabel *label3 = [self createAccountLabel:CGRectMake(10, label2.bottom, 45, 25) andTitle:@"折扣："];
//    label3.font = [UIFont systemFontOfSize:14];
//    label3.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
//    
//    
//    self.discount = [self createAccountLabel:CGRectMake(label3.right, label3.top, 100,25) andTitle:DiscountRate];
//    
//    
//    //    self.discount = [self createAccountLabel:CGRectMake(label3.right, label3.top, 100,20) andTitle:single.buyerModel.zhekou];
//    self.discount.font = [UIFont systemFontOfSize:14];
//    //    self.discount = [self createAccountLabel:CGRectMake(label3.right, label3.top, 100,20) andTitle:@"45"];
//    
//    self.discount.textColor = [self colorWithHexString:@"#EB206B"];
    
    [self createrOffLineUI:CGRectMake(10, self.agentLevel.bottom+5, SCREEN_WIDTH-20, 0.5)];
    
    
    
    
    UILabel *labels4 = [self createAccountLabel:CGRectMake(10, self.agentLevel.bottom+10, 105, 25) andTitle:@"销售额（总计）:"];
    labels4.font = [UIFont systemFontOfSize:14];
    labels4.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    //    self.sales = [self createAccountLabel:CGRectMake(labels4.right, labels4.top, 100, 25) andTitle:single.buyerModel.xiaoshoue];
    NSLog(@"%d",[self isBlankString:SellAmount]);
    if ([self isBlankString:SellAmount]) {
        self.sales = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels4.top, SCREEN_WIDTH/2-10, 25) andTitle:@"0"];
    }else{
        self.sales = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels4.top, SCREEN_WIDTH/2-10, 25) andTitle:SellAmount];
    }
    NSLog(@"%2f",SCREEN_WIDTH-10-labels4.right);
    
    
    //    self.sales = [self createAccountLabel:CGRectMake(self.view.frame.size.width-110, labels4.top, 100, 25) andTitle:single.buyerModel.xiaoshoue30];
    self.sales.font = [UIFont systemFontOfSize:14];
    self.sales.textAlignment = NSTextAlignmentRight;
    self.sales.textColor = [self colorWithHexString:@"#EB206B"];
    
    
    //    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, labels4.bottom+5, SCREEN_WIDTH-20, 30)];
    //    [imageV setImage:[UIImage imageNamed:@"账户_11"]];
    //    [titleBgView addSubview:imageV];
    
    
    UILabel *labels5 = [self createAccountLabel:CGRectMake(10, labels4.bottom, 70, 25) andTitle:@"盈利:"];
    labels5.font = [UIFont systemFontOfSize:14];
    labels5.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    //    self.nexts = [self createAccountLabel:CGRectMake(labels5.right, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    
    if ([self isBlankString:SellAmount]) {
        self.nexts = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels5.top, SCREEN_WIDTH/2-10, 25) andTitle:@"0"];
    }else{
        self.nexts = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels5.top, SCREEN_WIDTH/2-10, 25) andTitle:ProfitAmount];
    }
    
    
    //    self.nexts = [self createAccountLabel:CGRectMake(self.view.frame.size.width-110, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    self.nexts.font = [UIFont systemFontOfSize:14];
    
    self.nexts.textAlignment = NSTextAlignmentRight;
    self.nexts.textColor = [UIColor blackColor];
    
    [self createrOffLineUI:CGRectMake(10, labels5.bottom+5, SCREEN_WIDTH-20, 0.5)];
    
    
    UILabel *labels51 = [self createAccountLabel:CGRectMake(10, labels5.bottom+10, 70, 25) andTitle:@"账户金额:"];
    labels51.font = [UIFont systemFontOfSize:14];
    labels51.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    //    self.nexts = [self createAccountLabel:CGRectMake(labels5.right, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    
    if ([self isBlankString:SellAmount]) {
        self.ticheng = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels51.top, SCREEN_WIDTH/2-10, 25) andTitle:@"0"];
    }else{
        self.ticheng = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels51.top, SCREEN_WIDTH/2-10, 25) andTitle:AccountAmount];
    }
    
    
    //    self.nexts = [self createAccountLabel:CGRectMake(self.view.frame.size.width-110, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    self.ticheng.font = [UIFont systemFontOfSize:14];
    
    self.ticheng.textAlignment = NSTextAlignmentRight;
    self.ticheng.textColor = [self colorWithHexString:@"#EB206B"];
    
    
    UILabel *labels6 = [self createAccountLabel:CGRectMake(10, labels51.bottom, 70, 25) andTitle:@"可用:"];
    labels6.font = [UIFont systemFontOfSize:14];
    labels6.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    //    self.nexts = [self createAccountLabel:CGRectMake(labels5.right, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    
    NSInteger total = [AccountAmount integerValue];
    NSInteger freeze = [FreezeAmount integerValue];
    NSInteger keyong = total - freeze;
    
    self.keyong = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels51.bottom, SCREEN_WIDTH/2-10, 25) andTitle:[NSString stringWithFormat:@"%ld",(long)keyong]];
    
    zKeyong =[NSString stringWithFormat:@"%ld",(long)keyong];
    //    self.nexts = [self createAccountLabel:CGRectMake(self.view.frame.size.width-110, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    self.keyong.font = [UIFont systemFontOfSize:14];
    
    self.keyong.textAlignment = NSTextAlignmentRight;
    self.keyong.textColor = [UIColor blackColor];
    
    
    UILabel *labels7 = [self createAccountLabel:CGRectMake(10, labels6.bottom, 70, 25) andTitle:@"冻结:"];
    labels7.font = [UIFont systemFontOfSize:14];
    labels7.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    //    self.nexts = [self createAccountLabel:CGRectMake(labels5.right, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    if ([self isBlankString:FreezeAmount]) {
        self.dongjie = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels6.bottom, SCREEN_WIDTH/2-10, 25) andTitle:@"0"];
    }else{
        self.dongjie = [self createAccountRight:CGRectMake(SCREEN_WIDTH/2, labels6.bottom, SCREEN_WIDTH/2-10, 25) andTitle:FreezeAmount];
    }
    
    
    //    self.nexts = [self createAccountLabel:CGRectMake(self.view.frame.size.width-110, labels5.top, 100, 25) andTitle:single.buyerModel.chae];
    self.dongjie.font = [UIFont systemFontOfSize:14];
    
    self.dongjie.textAlignment = NSTextAlignmentRight;
    self.dongjie.textColor = [UIColor blackColor];
    
    
    
    UIButton *tiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    tiBtn.frame=  CGRectMake(15, labels7.bottom+10, 135, 30);
    [tiBtn setBackgroundImage:[UIImage imageNamed:@"账户_3"] forState:UIControlStateNormal];
    [tiBtn addTarget:self action:@selector(clickTi) forControlEvents:UIControlEventTouchUpInside];
    [titleBgView addSubview:tiBtn];
    
    UIButton *tiLBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    tiLBtn.frame=  CGRectMake(SCREEN_WIDTH-135-15, labels7.bottom+10, 135, 30);
    [tiLBtn setBackgroundImage:[UIImage imageNamed:@"账户_05"] forState:UIControlStateNormal];
    [tiLBtn addTarget:self action:@selector(clickTiL) forControlEvents:UIControlEventTouchUpInside];
    [titleBgView addSubview:tiLBtn];
    
    
//    jiesuanView = [[UIView alloc]initWithFrame:CGRectMake(0, titleBgView.bottom+10, SCREEN_WIDTH,50)];
//    jiesuanView.backgroundColor = [UIColor whiteColor];
//    jiesuanView.userInteractionEnabled = YES;
//    [self.scroller addSubview:jiesuanView];
//    
//    UILabel *labelw = [self createAccountLabelw:CGRectMake(10, 15, 128, 20) andTitle:@"物流费（累计）:"];
//    labelw.font = [UIFont systemFontOfSize:14];
//    labelw.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
//    //结算物流费
//    UIButton *buttonw = [UIButton buttonWithType:UIButtonTypeCustom];
//    buttonw.frame = CGRectMake(SCREEN_WIDTH-95, 10, 85, 30) ;
//    [buttonw setImage:[UIImage imageNamed:@"结算物流费"] forState:UIControlStateNormal];
//    [buttonw addTarget:self action:@selector(jieSuan) forControlEvents:UIControlEventTouchUpInside];
//    [jiesuanView addSubview:buttonw];
    
    middleView = [[UIView alloc]initWithFrame:CGRectMake(0, titleBgView.bottom+10, SCREEN_WIDTH,90)];
    middleView.backgroundColor = [UIColor whiteColor];
    middleView.userInteractionEnabled = YES;
    [self.scroller addSubview:middleView];
    
    
    UILabel *label4 = [self createAccountLabel1:CGRectMake(10, 15, 98, 20) andTitle:@"密码安全等级："];
    label4.font = [UIFont systemFontOfSize:14];
    label4.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    self.securityLevel = [self createAccountLabel1:CGRectMake(label4.right, label4.top, 130, 20) andTitle:@"安全"];
    self.securityLevel.font = [UIFont systemFontOfSize:14];
    self.securityLevel.textColor = [UIColor colorWithRed:89/255.0 green:172/255.0 blue:37/255.0 alpha:1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(60, label4.bottom+10, 85, 30) ;
    [button2 setImage:[UIImage imageNamed:@"账户_11"] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(accountChangePwd) forControlEvents:UIControlEventTouchUpInside];
    [middleView addSubview:button2];
    
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    button3.frame = CGRectMake(button2.right+30, label4.bottom+10, 85, 30) ;
    [button3 setImage:[UIImage imageNamed:@"修改支付密码"] forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(accountChangePwd1) forControlEvents:UIControlEventTouchUpInside];
    [middleView addSubview:button3];

    paymentView = [[UIView alloc]initWithFrame:CGRectMake(0, middleView.bottom+10, SCREEN_WIDTH,40)];
    paymentView.backgroundColor = [UIColor whiteColor];
    paymentView.userInteractionEnabled = YES;
    [self.scroller addSubview:paymentView];
    
    paymentLabel = [self createAccountLabelPay:CGRectMake(10, 10, 98, 20) andTitle:@"需缴纳保证金:"];
    paymentLabel.font = [UIFont systemFontOfSize:14];
    paymentLabel.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];

    paymentValue = [self createAccountLabelPay:CGRectMake(paymentLabel.right,10, 100, 20) andTitle:DepositAmount];
    paymentValue.font = [UIFont systemFontOfSize:14];
    paymentValue.textAlignment = NSTextAlignmentLeft;
    paymentValue.textColor = [self colorWithHexString:@"#EB206B"];
    
    paymentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    paymentBtn.frame = CGRectMake(SCREEN_WIDTH-95, 5, 85, 30) ;
    
    [paymentBtn addTarget:self action:@selector(paymentClick) forControlEvents:UIControlEventTouchUpInside];
    [paymentView addSubview:paymentBtn];

    if ([self.IsPayOffDeposit isEqualToString:@"0"]) {
        //未缴纳保证金
        [paymentBtn setImage:[UIImage imageNamed:@"账户_033"] forState:UIControlStateNormal];
    } else {
        
        [paymentBtn setImage:[UIImage imageNamed:@"已缴纳_033"] forState:UIControlStateNormal];
        paymentBtn.userInteractionEnabled = NO;
    }
    
    settlementView = [[UIView alloc]initWithFrame:CGRectMake(0, paymentView.bottom+10, SCREEN_WIDTH,40)];
    settlementView.backgroundColor = [UIColor whiteColor];
    settlementView.userInteractionEnabled = YES;
    [self.scroller addSubview:settlementView];
    
    settlementLabel = [self createAccountLabelSet:CGRectMake(10, 10, 98, 20) andTitle:@"物流费(累计):"];
    settlementLabel.font = [UIFont systemFontOfSize:14];
    settlementLabel.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    settlementValue = [self createAccountLabelSet:CGRectMake(settlementLabel.right,10, 100, 20) andTitle:ExpressFeeTotal];
    settlementValue.font = [UIFont systemFontOfSize:14];
    settlementValue.textAlignment = NSTextAlignmentLeft;
    settlementValue.textColor = [self colorWithHexString:@"#EB206B"];
    
    settlementBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    settlementBtn.frame = CGRectMake(SCREEN_WIDTH-95, 5, 85, 30) ;
    [settlementBtn setImage:[UIImage imageNamed:@"账户---已缴纳_14"] forState:UIControlStateNormal];

    
    [settlementBtn addTarget:self action:@selector(settlementClick) forControlEvents:UIControlEventTouchUpInside];
    [settlementView addSubview:settlementBtn];
    
    
    belowView = [[UIView alloc]initWithFrame:CGRectMake(0, settlementView.bottom+10, SCREEN_WIDTH,60)];
    belowView.backgroundColor = [UIColor whiteColor];
    belowView.userInteractionEnabled = YES;
    [self.scroller addSubview:belowView];
    
    UILabel *label5 = [self createAccountLabel2:CGRectMake(10, 10, 70, 20) andTitle:@"我的上级:"];
    label5.font = [UIFont systemFontOfSize:14];
    label5.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    
    UILabel *label6 = [self createAccountLabel2:CGRectMake(label5.right, label5.top, 150, 20) andTitle:FatherAgentName];
    label6.font = [UIFont systemFontOfSize:14];
    label6.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    UILabel *label7 = [self createAccountLabel2:CGRectMake(10, label5.bottom, 70, 20) andTitle:@"联系电话:"];
    label7.font = [UIFont systemFontOfSize:14];
    label7.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    
    UILabel *label8 = [self createAccountLabel2:CGRectMake(label7.right, label7.top, 150, 20) andTitle:FatherPhone];
    label8.font = [UIFont systemFontOfSize:14];
    label8.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    bbView = [[UIView alloc]initWithFrame:CGRectMake(0, belowView.bottom+10, SCREEN_WIDTH,40)];
    bbView.backgroundColor = [UIColor whiteColor];
    bbView.userInteractionEnabled = YES;
    [self.scroller addSubview:bbView];
    
    
    
    UILabel *label71 = [self createAccountLabel3:CGRectMake(10, 10, 70, 20) andTitle:@"客服电话:"];
    label71.font = [UIFont systemFontOfSize:14];
    label71.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    
    UILabel *label81 = [self createAccountLabel3:CGRectMake(label7.right, label71.top, 150, 20) andTitle:MobileNumber];
    label81.font = [UIFont systemFontOfSize:14];
    label81.textColor = [UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1];
    
    
    
}

#pragma mark - 结算
-(void)settlementClick{
    SettViewController *sett = [[SettViewController alloc]init];
    [self.navigationController pushViewController:sett animated:YES];
}
#pragma mark - 缴纳
-(void)paymentClick{
    [self careteAlertPassword];
    self.boolbalance = @"0";
}
#pragma mark - 结算完成
-(void)jiesuanSuccess{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];

    views = [[UIView alloc]init];
    views.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT+100);
    views.userInteractionEnabled = YES;
    views.backgroundColor = [UIColor blackColor];
    views.alpha = 0.4;
    [window addSubview:views];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT/2-150, SCREEN_WIDTH-100, 140)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [window addSubview:alertView];
    
    UIImageView *leftRightImage = [[UIImageView alloc]initWithFrame:CGRectMake(70, 45, 20, 22)];
    leftRightImage.image = [UIImage imageNamed:@"dingdanchong"];
    [alertView addSubview:leftRightImage];
    
    
    //验证码输入错误
    UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(leftRightImage.right, leftRightImage.top, 100, 22)];
    alertLabel.text = @"结算完成";
    alertLabel.numberOfLines = 0;
    alertLabel.font = [UIFont systemFontOfSize:14];
    alertLabel.textAlignment = NSTextAlignmentLeft;
    [alertView addSubview:alertLabel];
    
    UIView *lines = [[UIView alloc] initWithFrame:CGRectMake(0, 140-31, alertView.frame.size.width, 0.5)];
    lines.backgroundColor = [UIColor grayColor];
    [alertView addSubview:lines];
    
    
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, alertLabel.bottom+50-3, alertView.frame.size.width, 31);
    //leftBtn.backgroundColor= [ UIColor whiteColor];
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    [leftBtn addTarget:self action:@selector(clickTongGuo) forControlEvents:UIControlEventTouchUpInside];
    
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-07"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"weixindengluhou-07"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];

}
#pragma mark - 结算完成
-(void)clickTongGuo{
    [views removeFromSuperview];
    [alertView removeFromSuperview];
}
#pragma mark - 余额不足
-(void)createYue{
    
    UIWindow *windows = [[[UIApplication sharedApplication] delegate] window];
    
    zBack = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    zBack.backgroundColor = [UIColor blackColor];
    zBack.alpha = 0.4;
    [windows addSubview:zBack];
    
    alertView = [[UIView alloc]initWithFrame:CGRectMake(60, SCREEN_HEIGHT/2-70, SCREEN_WIDTH-120, 140)];
    alertView.backgroundColor = [UIColor whiteColor];
    alertView.userInteractionEnabled = YES;
    alertView.layer.cornerRadius = 10;//设置那个圆角的有多圆
    [windows addSubview:alertView];
    
    UILabel *alertLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 30, alertView.frame.size.width-40, 20)];
    alertLabel.text = @"余额不足";
    alertLabel.numberOfLines = 0;
    alertLabel.font = [UIFont systemFontOfSize:14];
    alertLabel.textColor = [self colorWithHexString:@"#EC3472"];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:alertLabel];
    
    UILabel *alertLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(20, alertLabel.bottom, alertView.frame.size.width-40, 20)];
    alertLabel1.text = @"请检查银行卡内余额";
    alertLabel1.numberOfLines = 0;
    alertLabel1.font = [UIFont systemFontOfSize:12];
    alertLabel1.textColor = [UIColor blackColor];
    alertLabel1.textAlignment = NSTextAlignmentCenter;
    [alertView addSubview:alertLabel1];
    
//    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(alertLabel.right+10, 40, 20, 20)];
//    [button setBackgroundImage:[UIImage imageNamed:@"购物车_07"] forState:UIControlStateNormal];
//    [button setBackgroundImage:[UIImage imageNamed:@"购物车２_07"] forState:UIControlStateSelected];
//    [button addTarget:self action:@selector(selectBut:) forControlEvents:UIControlEventTouchUpInside];
//    [alertView addSubview:button];

    
    UIView *lines = [[UIView alloc] initWithFrame:CGRectMake(0, 140-29, alertView.frame.size.width, 0.5)];
    lines.backgroundColor = [UIColor grayColor];
    [alertView addSubview:lines];


    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, alertView.frame.size.height-28, alertView.frame.size.width, 28);
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:leftBtn.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = leftBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    leftBtn.layer.mask = maskLayer1;
    
    [leftBtn addTarget:self action:@selector(cliclRight) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setImage:[UIImage imageNamed:@"账户---提现---弹窗_06"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"账户---提现---弹窗_06"] forState:UIControlStateHighlighted];
    [alertView addSubview:leftBtn];

    
    NSString *title = [NSString stringWithFormat:@"请输入您的支付密码"];
    _zhiFuAlartView.titleAlart.text = title;

}
#pragma -mark 打勾按钮事件
-(void)selectBut:(UIButton *)sener{
    self.boolbalance = @"";
    sener.selected = !sener.selected;
    if (sener.selected) {
        //使用余额
        self.boolbalance = @"1";
        
    } else{
        //不使用余额
        self.boolbalance = @"0";
        
    }
}
-(void)clickLeft1{
    YoungAllData *data = [[YoungAllData alloc]init];
    data.delegate = self;
    [data payOff:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"] andTradePass:_zhiFuAlartView.password.text andIsUserBalance:self.boolbalance];
}
#pragma mark - 调用接口失败
-(void)requistFail{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    [zBack removeFromSuperview];
    zBack = nil;
    [alertView removeFromSuperview];
    alertView = nil;
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"网络异常,无法加载数据" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}
#pragma mark - 结算物流费用回调
-(void)payOff:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
        
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[sign objectForKey:@"reason"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
-(void)cliclRight{
    [zBack removeFromSuperview];
    zBack = nil;
    [alertView removeFromSuperview];
    alertView = nil;
    
}
#pragma -mark 提交订单时的弹出输入密码提示框
-(void)careteAlertPassword{
    
    UIWindow *windows = [[[UIApplication sharedApplication] delegate] window];
    
    _alertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _alertBackview.backgroundColor = [UIColor blackColor];
    _alertBackview.alpha = 0.4;
    [windows addSubview:_alertBackview];
    
    _zhiFuAlartView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_Cart_Xib" owner:self options:nil] objectAtIndexedSubscript:12];
    _zhiFuAlartView.frame = CGRectMake(60, SCREEN_HEIGHT/2-90, SCREEN_WIDTH-120, 140);
    _zhiFuAlartView.password.delegate = self;
    [_zhiFuAlartView.affirmBut addTarget:self action:@selector(affirmClick) forControlEvents:UIControlEventTouchUpInside];
    [_zhiFuAlartView.cancelBut addTarget:self action:@selector(cancelButClick) forControlEvents:UIControlEventTouchUpInside];
    [windows addSubview:_zhiFuAlartView];
    
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [_alertBackview addGestureRecognizer:singleTapGestureRecognizer];
    
    NSString *title = [NSString stringWithFormat:@"请输入您的支付密码"];
    _zhiFuAlartView.titleAlart.text = title;
}

- (void)singleTap{
 [_zhiFuAlartView.password resignFirstResponder];
}

#pragma mark - UItextField Delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    //    NSMutableString *text = [textField.text mutableCopy];
    //    [text replaceCharactersInRange:range withString:string];
    //    return ([text length] >= 6);
    return YES;
}

#pragma -mark 点击弹出框的确定交易
- (void)affirmClick{
    if (_zhiFuAlartView.password.text== nil ||[_zhiFuAlartView.password.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入支付密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    [_alertBackview removeFromSuperview];
    [_zhiFuAlartView removeFromSuperview];
    [GMDCircleLoader setOnView:self.view withTitle:@"验证中···" animated:YES];
    [self wuliu];
}
-(void)wuliu{
    YoungAllData *data = [[YoungAllData alloc]init];
    [data checkTrade:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"] andTradePass:_zhiFuAlartView.password.text];
    data.delegate = self;
    
}
-(void)checktrade:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"] isEqualToString:@"success"]) {
        //支付密码验证成功
        dispatch_async(dispatch_get_main_queue(), ^{
            //[self jiesuanSuccess];
            YoungAllData *data = [[YoungAllData alloc]init];
            [GMDCircleLoader setOnView:self.view withTitle:@"缴纳中···" animated:YES];
            [data baoZhengJinJie:[[NSUserDefaults standardUserDefaults]objectForKey:@"userID"] andTradePass:_zhiFuAlartView.password.text];
            data.delegate = self;
        });
        
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:[sign objectForKey:@"reason"]delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma mark - 缴纳回调
-(void)baoZhengPay:(NSDictionary *)sign{
    [GMDCircleLoader hideFromView:self.view animated:YES];
    if ([[sign objectForKey:@"status"]isEqualToString:@"success"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"缴纳成功"delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        paymentValue.text = @"0";
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"IsPayOffDeposit"];
        [paymentBtn setImage:[UIImage imageNamed:@"已缴纳_033"] forState:UIControlStateNormal];
        paymentBtn.userInteractionEnabled = NO;
        
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:[sign objectForKey:@"reason"]delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
#pragma -mark 点击弹出框的取消交易
- (void)cancelButClick{
    [_alertBackview removeFromSuperview];
    [_zhiFuAlartView removeFromSuperview];
}



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    
}

#pragma mark - 提现
-(void)clickTi{
    WithdrawViewController *withdraw = [[WithdrawViewController alloc]init];
    withdraw.nameStr = zName;
    withdraw.keYongStr = zKeyong;
    [self.navigationController pushViewController:withdraw animated:YES];
    
}
#pragma mark - 提现记录
-(void)clickTiL{
    WithDrawJiLuViewController *withdraw = [[WithDrawJiLuViewController alloc]init];
    [self.navigationController pushViewController:withdraw animated:YES];
}
#pragma mark - 充值记录
-(void)chargeButtonAction{
    RechargeRecordViewController *record = [[RechargeRecordViewController alloc]init];
    [self.navigationController pushViewController:record animated:YES];
}

#pragma mark - 充值
-(void)chargeButton{
    RechargeViewController *recharge = [[RechargeViewController alloc]init];
    [self.navigationController pushViewController:recharge animated:YES];
}

#pragma mark - 微代理制度说明
-(void)levelButton:(UIButton *)sender{
    LevelViewController *level = [[LevelViewController alloc]init];
    [self.navigationController pushViewController:level animated:YES];
    
}
#pragma mark - 授权
-(void)shouquanAction{
    
}

#pragma mark - 新闻资讯
-(void)newsButton{
    
}
#pragma mark - 资料下载
-(void)dataDownloadAction{
    
}
#pragma mark - 修改密码
-(void)accountChangePwd{
    SetPasswordViewController *set = [[SetPasswordViewController alloc]init];
    [self.navigationController pushViewController:set animated:YES];
}
#pragma mark - 修改支付密码
-(void)accountChangePwd1{
    SetPayViewController *pay = [[SetPayViewController alloc]init];
    [self.navigationController pushViewController:pay animated:YES];
}
-(void)createWhiteBgView:(float)y andHeight:(float)h{
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, y, [UIScreen mainScreen].bounds.size.width, h)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.scroller addSubview:whiteView];
}

-(UILabel *)createAccountLabel:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [titleBgView addSubview:label];
    //    [label release];
    return label ;
}

-(UILabel *)createAccountRight:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentRight;
    [titleBgView addSubview:label];
    //    [label release];
    return label ;
}
-(UILabel *)createAccountLabel2:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [belowView addSubview:label];
    //    [label release];
    return label ;
}
-(UILabel *)createAccountLabel3:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [bbView addSubview:label];
    //    [label release];
    return label ;
}
-(UILabel *)createAccountLabel1:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [middleView addSubview:label];
    //    [label release];
    return label ;
}
-(void)createrOffLineUI:(CGRect)rect{
    UIView *lines = [[UIView alloc] initWithFrame:rect];
    lines.backgroundColor = [UIColor grayColor];
    [titleBgView addSubview:lines];
}
-(UILabel *)createAccountLabelw:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [jiesuanView addSubview:label];
    //    [label release];
    return label ;
}

//缴纳金
-(UILabel *)createAccountLabelPay:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [paymentView addSubview:label];
    //    [label release];
    return label ;
}
//结算
-(UILabel *)createAccountLabelSet:(CGRect)frame andTitle:(NSString *)title{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment= NSTextAlignmentLeft;
    [settlementView addSubview:label];
    //    [label release];
    return label ;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

-(void)dealloc{
    
    self.name = nil;
    self.agentLevel = nil;
    self.discount = nil;
    self.margin = nil;
    self.securityLevel = nil;
    self.deposit = nil;
    self.totalSales = nil;
    self.profit = nil;
    self.sales = nil;
    self.nexts = nil;
    self.scroller = nil;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - color
//传入字符串返回RGB
- (UIColor *) colorWithHexString: (NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
    
}

@end
